<?php

/**
 * This is the model class for table "BILLET_INCIDENT".
 *
 * The followings are the available columns in table 'BILLET_INCIDENT':
 * @property integer $ID_BILLET_INCIDENT
 * @property integer $ID_PROBLEME_LOGICIEL
 * @property integer $ID_POSTE
 * @property integer $ID_EMETTEUR
 * @property integer $ID_PROBLEME_MATERIEL
 * @property string $DESCRIPTION_PROBLEME
 * @property string $URGENCE
 * @property string $DATE_OUVERTURE
 * @property string $DATE_FERMETURE
 * @property string $DATE_FIN_PREVUE
 * @property string $PIECE_JOINTE
 * @property double $RESOLU
 *
 * The followings are the available model relations:
 * @property AFFECTATION[] $aFFECTATIONs
 * @property PROBLEMELOGICIEL $iDPROBLEMELOGICIEL
 * @property PROBLEMEMATERIEL $iDPROBLEMEMATERIEL
 * @property EMETTEUR $iDEMETTEUR
 * @property POSTE $iDPOSTE
 * @property INTERVENTIONSREALISEES[] $iNTERVENTIONSREALISEESs
 */
class BILLETINCIDENT extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'BILLET_INCIDENT';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ID_POSTE, ID_EMETTEUR, DESCRIPTION_PROBLEME, DATE_OUVERTURE', 'required'),
			array('ID_PROBLEME_LOGICIEL, ID_POSTE, ID_EMETTEUR, ID_PROBLEME_MATERIEL, ID_MATERIEL, ID_LOGICIEL', 'numerical', 'integerOnly'=>true),
			array('RESOLU', 'numerical'),
			array('DESCRIPTION_PROBLEME', 'length', 'max'=>500),
			array('URGENCE, PIECE_JOINTE', 'length', 'max'=>50),
			array('DATE_FERMETURE, DATE_FIN_PREVUE', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('ID_BILLET_INCIDENT, ID_PROBLEME_LOGICIEL, ID_POSTE, ID_EMETTEUR, ID_PROBLEME_MATERIEL, ID_MATERIEL,ID_LOGICIEL, DESCRIPTION_PROBLEME, URGENCE, DATE_OUVERTURE, DATE_FERMETURE, DATE_FIN_PREVUE, PIECE_JOINTE, RESOLU', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'aFFECTATIONs' => array(self::HAS_MANY, 'AFFECTATION', 'ID_BILLET_INCIDENT'),
			'iDPROBLEMELOGICIEL' => array(self::BELONGS_TO, 'PROBLEMELOGICIEL', 'ID_PROBLEME_LOGICIEL'),
			'iDPROBLEMEMATERIEL' => array(self::BELONGS_TO, 'PROBLEMEMATERIEL', 'ID_PROBLEME_MATERIEL'),
			'iDEMETTEUR' => array(self::BELONGS_TO, 'EMETTEUR', 'ID_EMETTEUR'),
			'iDPOSTE' => array(self::BELONGS_TO, 'POSTE', 'ID_POSTE'),
			'iNTERVENTIONSREALISEESs' => array(self::HAS_MANY, 'INTERVENTIONSREALISEES', 'ID_BILLET_INCIDENT'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID_BILLET_INCIDENT' => 'Numéro',
			'ID_PROBLEME_LOGICIEL' => 'Id Probleme Logiciel',
			'ID_POSTE' => 'Identifiant du poste',
			'ID_EMETTEUR' => 'Id Emetteur',
			'ID_PROBLEME_MATERIEL' => 'Id Probleme Materiel',
			'ID_MATERIEL' => 'Id Materiel',
			'ID_LOGICIEL' => 'Id Logiciel',
			'DESCRIPTION_PROBLEME' => 'Description',
			'URGENCE' => 'Urgence',
			'DATE_OUVERTURE' => 'Date d\'ouverture',
			'DATE_FERMETURE' => 'Date de fermeture',
			'DATE_FIN_PREVUE' => 'Date de fin prévue',
			'PIECE_JOINTE' => 'Pièce jointe',
			'RESOLU' => 'Résolu',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID_BILLET_INCIDENT',$this->ID_BILLET_INCIDENT);
		$criteria->compare('ID_PROBLEME_LOGICIEL',$this->ID_PROBLEME_LOGICIEL);
		$criteria->compare('ID_POSTE',$this->ID_POSTE);
		$criteria->compare('ID_EMETTEUR',$this->ID_EMETTEUR);
		$criteria->compare('ID_PROBLEME_MATERIEL',$this->ID_PROBLEME_MATERIEL);
		$criteria->compare('ID_MATERIEL',$this->ID_MATERIEL);
		$criteria->compare('ID_LOGICIEL',$this->ID_LOGICIEL);
		$criteria->compare('DESCRIPTION_PROBLEME',$this->DESCRIPTION_PROBLEME,true);
		$criteria->compare('URGENCE',$this->URGENCE,true);
		$criteria->compare('DATE_OUVERTURE',$this->DATE_OUVERTURE,true);
		$criteria->compare('DATE_FERMETURE',$this->DATE_FERMETURE,true);
		$criteria->compare('DATE_FIN_PREVUE',$this->DATE_FIN_PREVUE,true);
		$criteria->compare('PIECE_JOINTE',$this->PIECE_JOINTE,true);
		$criteria->compare('RESOLU',$this->RESOLU);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return BILLETINCIDENT the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
